package com.ereach;

import java.util.*;

public class DemoHashSet {
    public static void main(String[] args) {
        Set<String> list = new HashSet<>();

        list.add("Monday");
        list.add("Tuesday");
        list.add("Wednesday");
        list.add("Thursday");
        list.add("Friday");
        list.add("Saturday");
        list.add("Sunday");

        System.out.println(list);

        System.out.println("===add another Monday, it will be ignored");
        list.add("Monday");
        System.out.println(list);

        System.out.println("===Create another hashset from existing hashset");
        Set<String> list2 = new HashSet<>(list);
        list2.add("Mon");
        list2.add("Tue");
        list2.add("Wed");
        list2.add("Thu");
        list2.add("Fri");
        list2.add("Sat");
        list2.add("Sun");
        System.out.println(list2);

        System.out.println("===hashset foreach loop");
        for (var x : list2)
            System.out.println(x);

        System.out.println("===forEach loop lambda expression");
        list2.forEach(x -> System.out.println(x));

        System.out.println("===get the size of a hashset");
        System.out.println(list2.size());

        System.out.println("===remove a specified element from a hashset");
        System.out.println(list2.remove("Mon"));
        System.out.println(list2);

        System.out.println("===remove elements form a specified list");
        List<String> mylist = new ArrayList<>();
        Collections.addAll(mylist, "Fri", "Sat", "Sun");
        list2.removeAll(mylist);
        System.out.println(list2);

        System.out.println("===clear method");
        list2.clear();
        System.out.println(list2);
    }
}
